﻿Imports lbGlobalcom
Public Class fTipoIva
    Dim daTipoIva As dsContabilidadTableAdapters.CON_TIPOIVATableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter

    Private Sub fTipoIva_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsContabilidad.CON_TIPOIVA.GetChanges IsNot Nothing Then
                CON_TIPOIVABindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CON_TIPOIVABindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub
    Private Sub fTipoIva_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daTipoIva = New dsContabilidadTableAdapters.CON_TIPOIVATableAdapter
            daClave = New dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCarga.Click
        Try
            If Me.DsContabilidad.CON_TIPOIVA.GetChanges IsNot Nothing Then
                CON_TIPOIVABindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CON_TIPOIVABindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daTipoIva.Fill(DsContabilidad.CON_TIPOIVA)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CON_TIPOIVABindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CON_TIPOIVABindingNavigatorSaveItem.Click
        Try
            Validate()
            CON_TIPOIVABindingSource.EndEdit()
            daTipoIva.Update(DsContabilidad.CON_TIPOIVA)
            MessageBox.Show("Se salvarón registros con exito", "Salva Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CON_TIPOIVADataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles CON_TIPOIVADataGridView.CellBeginEdit
        Try
            If e.ColumnIndex = 1 AndAlso CON_TIPOIVADataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
                Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
                dt = daClave.GetDataByIdClavePrimaria("CON_CCOSTO")
                If dt.Count Then
                    Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                    dr = dt.Rows(0)
                    Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                    CON_TIPOIVADataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                    Cons = Nothing
                    CON_TIPOIVABindingSource.EndEdit()
                    daTipoIva.Update(DsContabilidad.CON_TIPOIVA)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CON_TIPOIVADataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles CON_TIPOIVADataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub CON_TIPOIVADataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles CON_TIPOIVADataGridView.UserDeletedRow
        Try
            daTipoIva.Update(DsContabilidad.CON_TIPOIVA)
            MessageBox.Show("Se elimino registro con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub


    Private Sub CON_TIPOIVADataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles CON_TIPOIVADataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class